
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>设计原则 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../redis/about.html" />
    
    
    <link rel="prev" href="../../" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    READMI
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="design_principle.html">
            
                <a href="design_principle.html">
            
                    
                    设计原则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../redis/about.html">
            
                <a href="../redis/about.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../zookeeper/about.html">
            
                <a href="../zookeeper/about.html">
            
                    
                    Zookeeper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../aboutLinux/about.html">
            
                <a href="../aboutLinux/about.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >设计原则</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x8BBE;&#x8BA1;&#x539F;&#x5219;">&#x8BBE;&#x8BA1;&#x539F;&#x5219;</h2>
<p>Single Responsibility Principle&#xFF1A;&#x5355;&#x4E00;&#x804C;&#x8D23;&#x539F;&#x5219;</p>
<p>Open Closed Principle&#xFF1A;&#x5F00;&#x95ED;&#x539F;&#x5219;</p>
<p>Liskov Substitution Principle&#xFF1A;&#x91CC;&#x6C0F;&#x66FF;&#x6362;&#x539F;&#x5219;</p>
<p>Law of Demeter&#xFF1A;&#x8FEA;&#x7C73;&#x7279;&#x6CD5;&#x5219;</p>
<p>Interface Segregation Principle&#xFF1A;&#x63A5;&#x53E3;&#x9694;&#x79BB;&#x539F;&#x5219;</p>
<p>Dependence Inversion Principle&#xFF1A;&#x4F9D;&#x8D56;&#x5012;&#x7F6E;&#x539F;&#x5219;</p>
<h4 id="&#x5355;&#x4E00;&#x8D23;&#x4EFB;&#x539F;&#x5219;">&#x5355;&#x4E00;&#x8D23;&#x4EFB;&#x539F;&#x5219;</h4>
<p>There should never be more than one reason for a class to change.</p>
<p>&#x5355;&#x4E00;&#x804C;&#x8D23;&#x539F;&#x5219;&#x8981;&#x6C42;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x6216;&#x8005;&#x7C7B;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x539F;&#x56E0;&#x5F15;&#x8D77;&#x53D8;&#x5316;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x6216;&#x8005;&#x7C7B;&#x53EA;&#x8D1F;&#x8D23;&#x4E00;&#x4EF6;&#x4E8B;&#x60C5;&#xFF1B;</p>
<p>&#x5BF9;&#x8C61;&#x5206;&#x6E05;&#x8D23;&#x4EFB;&#xFF0C;&#x5C3D;&#x91CF;&#x5355;&#x4E00;&#x8D23;&#x4EFB;&#x3002;</p>
<h4 id="&#x91CC;&#x6C0F;&#x66FF;&#x6362;&#x539F;&#x5219;">&#x91CC;&#x6C0F;&#x66FF;&#x6362;&#x539F;&#x5219;</h4>
<p>If for each object 01 of type S there is an object 02 for type T such that for all programs P defined in terms of T,the behavior of P is unchanged when 01 is substituted for 02 then S is a subtype of T.</p>
<p>&#x5982;&#x679C;&#x5BF9;&#x6BCF;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x4E3A;S&#x7684;&#x5BF9;&#x8C61;o1&#xFF0C;&#x90FD;&#x6709;&#x7C7B;&#x578B;&#x4E3A;T&#x7684;&#x5BF9;&#x8C61;o2&#xFF0C;&#x4F7F;&#x5F97;&#x4EE5;T&#x5B9A;&#x4E49;&#x7684;&#x6240;&#x6709;&#x7A0B;&#x5E8F;P&#x5728;&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;o1&#x90FD;&#x4EE3;&#x6362;&#x6210;o2&#x65F6;&#xFF0C;&#x7A0B;&#x5E8F;P&#x7684;&#x884C;&#x4E3A;&#x6CA1;&#x6709;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF0C;&#x90A3;&#x4E48;&#x7C7B;&#x578B;S&#x662F;&#x7C7B;&#x578B;T&#x7684;&#x5B50;&#x7C7B;&#x578B;&#x3002;</p>
<p>&#x7236;&#x7C7B;&#x80FD;&#x5B9E;&#x73B0;&#x7684;&#x5B50;&#x7C7B;&#x90FD;&#x53EF;&#x4EE5;&#xFF1B;&#x7236;&#x7C7B;&#x76F4;&#x63A5;&#x66FF;&#x6362;&#x6210;&#x5B50;&#x7C7B;&#x4E5F;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#xFF1B;</p>
<p>&#x91C7;&#x7528;&#x91CC;&#x6C0F;&#x66FF;&#x6362;&#x539F;&#x5219;&#x65F6;&#xFF0C;&#x5C3D;&#x91CF;&#x907F;&#x514D;&#x5B50;&#x7C7B;&#x7684;&#x201C;&#x4E2A;&#x6027;&#x201D;&#xFF0C;&#x4E00;&#x65E6;&#x5B50;&#x7C7B;&#x6709;&#x201C;&#x4E2A;&#x6027;&#x201D;&#xFF0C;&#x8FD9;&#x4E2A;&#x5B50;&#x7C7B;&#x548C;&#x7236;&#x7C7B;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x7CFB;&#x5C31;&#x5F88;&#x96BE;&#x8C03;&#x548C;&#x4E86;&#xFF0C;&#x628A;&#x5B50;&#x7C7B;&#x5F53;&#x505A;&#x7236;&#x7C7B;&#x4F7F;&#x7528;&#xFF0C;&#x5B50;&#x7C7B;&#x7684;&#x201C;&#x4E2A;&#x6027;&#x201D;&#x88AB;&#x62B9;&#x6740;&#x2014;&#x2014;&#x59D4;&#x5C48;&#x4E86;&#x70B9;&#xFF1B;&#x628A;&#x5B50;&#x7C7B;&#x5355;&#x72EC;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x4E1A;&#x52A1;&#x6765;&#x4F7F;&#x7528;&#xFF0C;&#x5219;&#x4F1A;&#x8BA9;&#x4EE3;&#x7801;&#x95F4;&#x7684;&#x8026;&#x5408;&#x5173;&#x7CFB;&#x53D8;&#x5F97;&#x6251;&#x6714;&#x8FF7;&#x79BB;&#x2014;&#x2014;&#x7F3A;&#x4E4F;&#x7C7B;&#x66FF;&#x6362;&#x7684;&#x6807;&#x51C6;&#x3002;</p>
<h4 id="&#x4F9D;&#x8D56;&#x5012;&#x7F6E;&#x539F;&#x5219;">&#x4F9D;&#x8D56;&#x5012;&#x7F6E;&#x539F;&#x5219;</h4>
<p>High level modules should not depend upon low level modules.Both shoulddepend upon abstractions.Abstractions should not depend upondetails.Details should depend upon abstractions.</p>
<p>&#x9AD8;&#x5C42;&#x6A21;&#x5757;&#x4E0D;&#x5E94;&#x8BE5;&#x4F9D;&#x8D56;&#x4F4E;&#x5C42;&#x6A21;&#x5757;&#xFF0C;&#x4E24;&#x8005;&#x90FD;&#x5E94;&#x8BE5;&#x4F9D;&#x8D56;&#x5176;&#x62BD;&#x8C61;&#xFF1B;&#x62BD;&#x8C61;&#x4E0D;&#x5E94;&#x8BE5;&#x4F9D;&#x8D56;&#x7EC6;&#x8282;&#xFF1B;&#x7EC6;&#x8282;&#x5E94;&#x8BE5;&#x4F9D;&#x8D56;&#x62BD;&#x8C61;&#x3002;</p>
<p>&#x9AD8;&#x5C42;&#x6A21;&#x5757;&#x548C;&#x4F4E;&#x5C42;&#x6A21;&#x5757;&#x5BB9;&#x6613;&#x7406;&#x89E3;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x903B;&#x8F91;&#x7684;&#x5B9E;&#x73B0;&#x90FD;&#x662F;&#x7531;&#x539F;&#x5B50;&#x903B;&#x8F91;&#x7EC4;&#x6210;&#x7684;&#xFF0C;&#x4E0D;&#x53EF;&#x5206;&#x5272;&#x7684;&#x539F;&#x5B50;&#x903B;&#x8F91;&#x5C31;&#x662F;&#x4F4E;&#x5C42;&#x6A21;&#x5757;&#xFF0C;&#x539F;&#x5B50;&#x903B;&#x8F91;&#x7684;&#x518D;&#x7EC4;&#x88C5;&#x5C31;&#x662F;&#x9AD8;&#x5C42;&#x6A21;&#x5757;&#x3002;&#x90A3;&#x4EC0;&#x4E48;&#x662F;&#x62BD;&#x8C61;&#xFF1F;&#x4EC0;&#x4E48;&#x53C8;&#x662F;&#x7EC6;&#x8282;&#x5462;&#xFF1F;&#x5728;Java&#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x62BD;&#x8C61;&#x5C31;&#x662F;&#x6307;&#x63A5;&#x53E3;&#x6216;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x4E24;&#x8005;&#x90FD;&#x662F;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x88AB;&#x5B9E;&#x4F8B;&#x5316;&#x7684;&#xFF1B;&#x7EC6;&#x8282;&#x5C31;&#x662F;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x6216;&#x7EE7;&#x627F;&#x62BD;&#x8C61;&#x7C7B;&#x800C;&#x4EA7;&#x751F;&#x7684;&#x7C7B;&#x5C31;&#x662F;&#x7EC6;&#x8282;&#xFF0C;&#x5176;&#x7279;&#x70B9;&#x5C31;&#x662F;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x88AB;&#x5B9E;&#x4F8B;&#x5316;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x53EF;&#x4EE5;&#x52A0;&#x4E0A;&#x4E00;&#x4E2A;&#x5173;&#x952E;&#x5B57;new&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</p>
<p><img src="image-20200728172905539.png" alt="image-20200728172905539"></p>
<h4 id="&#x63A5;&#x53E3;&#x9694;&#x79BB;&#x539F;&#x5219;">&#x63A5;&#x53E3;&#x9694;&#x79BB;&#x539F;&#x5219;</h4>
<p>Clients should not be forced to depend upon interfaces that they don&apos;t use.</p>
<p>&#xFF08;&#x5BA2;&#x6237;&#x7AEF;&#x4E0D;&#x5E94;&#x8BE5;&#x4F9D;&#x8D56;&#x5B83;&#x4E0D;&#x9700;&#x8981;&#x7684;&#x63A5;&#x53E3;&#xFF09;</p>
<p>The dependency of one class to another one should depend on thesmallest possible interface.&#xFF08;&#x7C7B;&#x95F4;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x5E94;&#x8BE5;&#x5EFA;&#x7ACB;&#x5728;&#x6700;&#x5C0F;&#x7684;&#x63A5;&#x53E3;&#x4E0A;&#x3002;&#xFF09;</p>
<p><img src="image-20200728172732836.png" alt="image-20200728172732836"></p>
<p>&#x63A5;&#x53E3;&#x4E0D;&#x80FD;&#x8FDD;&#x80CC;&#x5355;&#x4E00;&#x804C;&#x8D23;&#xFF0C;&#x5C3D;&#x91CF;&#x7EAF;&#x6D01;&#x3002;&#x4E0D;&#x81C3;&#x80BF;&#xFF1B;</p>
<h4 id="&#x8FEA;&#x7C73;&#x7279;&#x6CD5;&#x5219;">&#x8FEA;&#x7C73;&#x7279;&#x6CD5;&#x5219;</h4>
<p>&#x4E5F;&#x79F0;&#x4E3A;&#x6700;&#x5C11;&#x77E5;&#x8BC6;&#x539F;&#x5219;</p>
<p>&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x5E94;&#x8BE5;&#x5BF9;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x6709;&#x6700;&#x5C11;&#x7684;&#x4E86;&#x89E3;</p>
<p>&#x5C3D;&#x91CF;&#x7684;&#x89E3;&#x8026;&#x5176;&#x4ED6;&#x7684;&#x7C7B;&#x3002;&#x804C;&#x8D23;&#x5355;&#x4E00;&#xFF1B;</p>
<p>&#x8FEA;&#x7C73;&#x7279;&#x6CD5;&#x5219;&#x7684;&#x6838;&#x5FC3;&#x89C2;&#x5FF5;&#x5C31;&#x662F;&#x7C7B;&#x95F4;&#x89E3;&#x8026;&#xFF0C;&#x5F31;&#x8026;&#x5408;&#xFF0C;&#x53EA;&#x6709;&#x5F31;&#x8026;&#x5408;&#x4E86;&#x4EE5;&#x540E;&#xFF0C;&#x7C7B;&#x7684;&#x590D;&#x7528;&#x7387;&#x624D;&#x53EF;&#x4EE5;&#x63D0;&#x9AD8;&#x3002;&#x5176;&#x8981;&#x6C42;&#x7684;&#x7ED3;&#x679C;&#x5C31;&#x662F;&#x4EA7;&#x751F;&#x4E86;&#x5927;&#x91CF;&#x7684;&#x4E2D;&#x8F6C;&#x6216;&#x8DF3;&#x8F6C;&#x7C7B;&#xFF0C;&#x5BFC;&#x81F4;&#x7CFB;&#x7EDF;&#x7684;&#x590D;&#x6742;&#x6027;&#x63D0;&#x9AD8;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x4E3A;&#x7EF4;&#x62A4;&#x5E26;&#x6765;&#x4E86;&#x96BE;&#x5EA6;&#x3002;&#x8BFB;&#x8005;&#x5728;&#x91C7;&#x7528;&#x8FEA;&#x7C73;&#x7279;&#x6CD5;&#x5219;&#x65F6;&#x9700;&#x8981;&#x53CD;&#x590D;&#x6743;&#x8861;&#xFF0C;&#x65E2;&#x505A;&#x5230;&#x8BA9;&#x7ED3;&#x6784;&#x6E05;&#x6670;&#xFF0C;&#x53C8;&#x505A;&#x5230;&#x9AD8;&#x5185;&#x805A;&#x4F4E;&#x8026;&#x5408;&#x3002;</p>
<h4 id="&#x5F00;&#x95ED;&#x539F;&#x5219;">&#x5F00;&#x95ED;&#x539F;&#x5219;</h4>
<p>Software entities like classes,modules and functions should be open forextension but closed for modifications.&#xFF08;&#x4E00;&#x4E2A;&#x8F6F;&#x4EF6;&#x5B9E;&#x4F53;&#x5982;&#x7C7B;&#x3001;&#x6A21;&#x5757;&#x548C;&#x51FD;&#x6570;&#x5E94;&#x8BE5;&#x5BF9;&#x6269;&#x5C55;&#x5F00;&#x653E;&#xFF0C;&#x5BF9;&#x4FEE;&#x6539;&#x5173;&#x95ED;&#x3002;&#xFF09;</p>
<p>&#x5F00;&#x95ED;&#x539F;&#x5219;&#x53EF;&#x4EE5;&#x63D0;&#x9AD8;&#x53EF;&#x7EF4;&#x62A4;&#x6027;</p>
<p>1.&#x62BD;&#x8C61;&#x7EA6;&#x675F;</p>
<p>2.&#x5143;&#x6570;&#x636E;&#xFF08;metadata&#xFF09;&#x63A7;&#x5236;&#x6A21;&#x5757;&#x884C;&#x4E3A;</p>
<p>3.&#x5236;&#x5B9A;&#x9879;&#x76EE;&#x7AE0;&#x7A0B;</p>
<p>4.&#x5C01;&#x88C5;&#x53D8;&#x5316;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../../" class="navigation navigation-prev " aria-label="Previous page: READMI">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../redis/about.html" class="navigation navigation-next " aria-label="Next page: Redis">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"设计原则","level":"1.2","depth":1,"next":{"title":"Redis","level":"1.3","depth":1,"path":"post/redis/about.md","ref":"post/redis/about.md","articles":[]},"previous":{"title":"READMI","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"post/design/design_principle.md","mtime":"2020-07-28T09:34:38.366Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-10-29T08:21:27.014Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

